package com.example.myapplication.apter;

import android.app.Activity;
import android.content.Intent;
import android.text.TextUtils;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.ScrollView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.bumptech.glide.Glide;
import com.example.myapplication.Config.Commom;
import com.example.myapplication.Config.TokenBean;
import com.example.myapplication.R;
import com.example.myapplication.ShuJu.RouteclassificationBean;
import com.example.myapplication.urbansubway.RoutedetailsActivity;

import java.util.List;

public class RouteclassificationApter extends RecyclerView.Adapter<RouteclassificationApter.Myhot> {
    private Activity context;
    private View view;
    private List<RouteclassificationBean.DataDTO> list;

    public RouteclassificationApter(Activity context, List<RouteclassificationBean.DataDTO> list) {
        this.context = context;
        this.list = list;
    }

    @NonNull
    @Override
    public RouteclassificationApter.Myhot onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        view = LayoutInflater.from(context).inflate(R.layout.item_routeclassification,null);
        return new RouteclassificationApter.Myhot(view);
    }

    @Override
    public void onBindViewHolder(@NonNull RouteclassificationApter.Myhot holder, int position) {
       if(!TextUtils.isEmpty(list.get(position).getCurrentName())){
           holder.currentName.setText("当前站点: "+list.get(position).getCurrentName());
       }
        if(list.get(position).getReachTime() !=null ){
            holder.reachTime.setText("间隔时间: "+String.valueOf(list.get(position).getReachTime())+"分钟");
        }
        RouteclassificationBean.DataDTO.NextStepDTO nextStep = list.get(position).getNextStep();
       if(nextStep !=null){
           holder.name.setText("下一站"+nextStep.getName());
           List<RouteclassificationBean.DataDTO.NextStepDTO.LinesDTO> lines = nextStep.getLines();
           if(lines!=null){
               holder.lineName.setText(lines.get(position).getLineName());
           }

       }

       //路线详情
        holder.re_houserapter.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(context, RoutedetailsActivity.class);
                intent.putExtra(Commom.ROUTEDETAILSID,String.valueOf(list.get(position).getLineId()));
                context.startActivity(intent);
            }
        });
    }

    @Override
    public int getItemCount() {
        return list==null?0:list.size();
    }

    class Myhot extends RecyclerView.ViewHolder{



        private final TextView lineName;
        private final TextView currentName;
        private final TextView reachTime;
        private final TextView name;
        private final RelativeLayout re_houserapter;

        public Myhot(@NonNull View itemView) {
            super(itemView);
            currentName = itemView.findViewById(R.id.currentName);
            lineName = itemView.findViewById(R.id.lineName);
            reachTime = itemView.findViewById(R.id.reachTime);
            name = itemView.findViewById(R.id.name);
            re_houserapter = itemView.findViewById(R.id.re_houserapter);
        }
    }
}

